package com.mango.leet.code.week2.game375;

/**
 * https://leetcode.cn/contest/weekly-contest-375/problems/count-tested-devices-after-test-operations/
 *
 */
public class LC100143 {
    public static int countTestedDevices(int[] batteryPercentages) {
        int result = 0;
        for (int i = 0; i < batteryPercentages.length; i++) {
            if (batteryPercentages[i] > 0) {
                result++;
                int j = i + 1;
                while (j < batteryPercentages.length) {
                    batteryPercentages[j++]--;
                }
            }
        }
        return result;
    }

    public static void main(String[] args) {
       //int[] batteryPercentages = {1,1,2,1,3};
       int[] batteryPercentages = {0,1,2};
       System.out.println(countTestedDevices(batteryPercentages));
    }
}
